package com.googlecode.agscrum.controller.jsf.bean;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.googlecode.agscrum.model.entity.Product;
import com.googlecode.agscrum.model.service.Service;
import com.googlecode.agscrum.model.util.Criteria;
import com.googlecode.agscrum.model.util.Restrictions;

@Controller("lookupControllerBean")
@Configurable(autowire = Autowire.BY_NAME)
@Scope("request")
public class LookupControllerBean {

	private Service<Product, Long> productService;

	public void setProductService(Service<Product, Long> productService) {
		this.productService = productService;
	}

	public List<Product> getAllProductActive() {
		Criteria criteria = Criteria.getInstance("Product.searchQuery",
				Product.class).addAnd(Restrictions.eq("p.active", true))
				.setCacheable(true);
		List<Product> products = productService.readByCriteria(criteria);
		return products;
	}

}
